<template>
	<view class="cardItem">
		<view class="cardItem_top">
			<view class="cardItem_top_right">
				<view class="cardItem_top_right_btn" :style='colorordersStatusType(Number(orderObj.ordersStatusId))'>
					{{orderObj.ordersStatus}}
				</view>
				<view class="cardItem_top_right_btn" :style='colorType(Number(orderObj.serviceStatusId))'>
					{{orderObj.serviceStatus}}
				</view>

			</view>
			<view class="cardItem_top_left">
				<view class="cardItem_top_left_btn" :style='sendingStatusType(orderObj.sendingType)'>
					{{orderObj.sendingType}}
				</view>
				<view class="cardItem_top_left_btn" :style='receiveStatusType(orderObj)'>
					{{orderObj.receiveStatusTxt}}
				</view>
			</view>
		</view>

		<view class="cardItem_infosContaines">
			<view class="cardItem_infosContaines_content">

				<view class="cardItem_infosContaines_content_item" v-if="orderObj.expressNumber">
					<view class="cardItem_infosContaines_content_item_label ">
						快递单号
					</view>
					<view class="cardItem_infosContaines_content_item_title">
						{{orderObj.expressNumber}}
					</view>
				</view>
				<view class="cardItem_infosContaines_content_item">
					<view class="cardItem_infosContaines_content_item_label ">
						订单ID
					</view>
					<view class="cardItem_infosContaines_content_item_title">
						{{orderObj.orderId}}
					</view>
				</view>
				<view class="cardItem_infosContaines_content_item">
					<view class="cardItem_infosContaines_content_item_label ">
						订单号
					</view>
					<view class="cardItem_infosContaines_content_item_title">
						{{orderObj.serialNumber}}
					</view>
				</view>

				<view class="cardItem_infosContaines_content_item">
					<view class="cardItem_infosContaines_content_item_label ">
						患者信息
					</view>
					<view class="cardItem_infosContaines_content_item_title_infos">
						<view class="cardItem_infosContaines_content_item_title_infos_name">
							{{orderObj.name}}
						</view>
						<view class="cardItem_infosContaines_content_item_title_infos_line" v-if="orderObj.sexName">

						</view>
						<view class="cardItem_infosContaines_content_item_title_infos_name" v-if="orderObj.sexName">
							{{orderObj.sexName}}
						</view>

						<view class="cardItem_infosContaines_content_item_title_infos_line" v-if="orderObj.age">

						</view>
						<view class="cardItem_infosContaines_content_item_title_infos_name" v-if="orderObj.age">
							{{orderObj.age}}
						</view>

					</view>
				</view>

				<view class="cardItem_infosContaines_content_item" v-if='orderObj.sendingCourier'>
					<view class="cardItem_infosContaines_content_item_label ">
						寄件机构
					</view>
					<view class="cardItem_infosContaines_content_item_title_infos">
						<view class="cardItem_infosContaines_content_item_title_infos_name">
							{{orderObj.sendingCourier}}
						</view>

					</view>
				</view>
				<view class="cardItem_infosContaines_content_item">
					<view class="cardItem_infosContaines_content_item_label ">
						寄件人
					</view>
					<view class="cardItem_infosContaines_content_item_title_infos">
						<view class="cardItem_infosContaines_content_item_title_infos_name">
							{{orderObj.expressContent.consignor}}
						</view>

					</view>
				</view>
				<view class="cardItem_infosContaines_content_item" v-if='orderObj.sendTime'>
					<view class="cardItem_infosContaines_content_item_label ">
						寄送日期
					</view>
					<view class="cardItem_infosContaines_content_item_title">
						{{orderObj.sendTime}}
					</view>
				</view>
				<view class="cardItem_infosContaines_content_item" v-if="orderObj.sendNumber">
					<view class="cardItem_infosContaines_content_item_label ">
						第几次寄送
					</view>
					<view class="cardItem_infosContaines_content_item_title">
						{{orderObj.sendNumber}}
					</view>
				</view>
				<view class="cardItem_infosContaines_content_item" v-if='orderObj.receivingCourier'>
					<view class="cardItem_infosContaines_content_item_label ">
						接收机构
					</view>
					<view class="cardItem_infosContaines_content_item_title_infos">
						<view class="cardItem_infosContaines_content_item_title_infos_name">
							{{orderObj.receivingCourier}}
						</view>

					</view>
				</view>


			</view>
		</view>
		<view class="cardItem_bottom">
			<view class="cardItem_bottom_btnGroup">
				<view class="cardItem_bottom_btnGroup_item" v-for="(item, index) in btnGroupArr" :key="index">
					<block v-if="buttonVisibleFunc(item.functionKey, orderObj)">
						<view class="cardItem_bottom_btnGroup_item_btn" @tap="clickButton(item.functionKey, orderObj)">
							{{item.label}}
						</view>
					</block>

				</view>

			</view>
		</view>
	</view>

</template>

<script>
	import {
		mapState
	} from 'vuex'
	import {
		serviceStatusMap,
		ningboOrderTypeMap,
		ordersStatusMap
	} from '@/utils/baseData.js'

	export default {
		name: "orderItem",
		props: ['orderObj', 'title', 'itemIndex', 'btnGroupArr'], //entranceType  1:专家介绍进入 2:特需会诊进入
		computed: {
			...mapState({
				currentinstitutionId: state => state.user.institution.id,
				logInType: state => state.user.logInType, //用户身份 1医生  2个人  普通
			}),
		},
		data() {
			return {
				serviceStatusMap: serviceStatusMap,
				ningboOrderTypeMap: ningboOrderTypeMap,
				ordersStatusMap: ordersStatusMap,

			}
		},
		created() {

		},
		methods: {
			buttonVisibleFunc(func, rowData) {
				let that = this
				if (this.logInType == 1) {
					if (this.currentinstitutionId && this.currentinstitutionId != 1) { //非admin账号
						if (func == 'back') { // 回寄
							if (rowData.receiveStatus != 1) {
								return false
							} else if (rowData.receiveStatus == 1 && rowData.sendingType == '回寄') {
								return false
							} else {
								return true
							}

						} else if (func == 'receive') {
							if ((rowData.sendingType == '回寄' && rowData.receiveStatus != 3 && rowData.receiveStatus ==
									4) ||
								rowData.receiveStatus == 3 || rowData.receiveStatus == 4) {
								return false
							} else if ((rowData.sendingType == '寄送' || rowData.sendingType == '回寄') && rowData
								.receivingCourierId != this.currentinstitutionId) {
								return false
							} else if (rowData.receiveStatus == 1) {
								return false
							} else {
								return true
							}
						} else if (func == 'send') { //新增
							if (rowData.receivingCourierId == this.currentinstitutionId) {
								return false
							} else if (rowData.sendingType == '回寄') {
								return false
							} else {
								return true
							}
						} else {
							return true
						}
					} else {
						if (func == 'back' || func == 'receive' || func == 'send') { // 回寄
							return false
						} else {
							return true
						}
					}
				} else if (this.logInType == 2) {
					if (func == 'back') { // 回寄
						return false
					} else if (func == 'receive') {
						if (rowData.sendingType == '回寄' && rowData.receiveStatus == 2 ) {
							return true
						} else {
							return false
						}
					} else {
						return true
					}
				}

			},
			getColorFromRow(row, item) {
				if (row && row.receiveWithoutSignInCount > 0 && item.label == '快递') {
					return 'red'
				} else if (item.functionKey == 'picScan' && row.id == item.viewOrderId) { //
					return '#999999'
				} else {
					return '#266EFF'
				}

			},
			// 按钮点击
			clickButton(functionKey, row, item) {
				// return
				if (item && item.viewOrderId == row.id) {
					// this.$message.warning('当前浏览的')
					return false
				}
				this.$emit('handleClick', functionKey, row)
			},
			getexpertName(item) {
				if (item && item.patients[0]) {
					if (item.patients[0].expertDiagnosis && item.patients[0].expertDiagnosis[0]) {
						return item.patients[0].expertDiagnosis[0].expertName
					} else {
						return ''
					}
				} else {
					return ''
				}
			},
			sendingStatusType(item) {
				switch (item) {
					case '寄送':
						return {
							'background-color': '#f0f9eb', 'border-color': '#409EFF', color: '#409EFF'
						} //success
					case '回寄':
						return {
							'background-color': '#fdf6ec', 'border-color': '#faea95', color: '#E6A23C'
						} //danger
					default:
						return {
							'background-color': '#fef0f0', 'border-color': '#fde2e2', color: '#f56c6c'
						} //success
				}
			},
			receiveStatusType(item) {
				if (item.receiveStatus === 2 || (item.receiveStatus == 1 && item.sendingType == '寄送')) {
					return {
						'background-color': '#fff',
						'border-color': '#fd2f28',
						color: '#f53c17'
					}
				} else if (item.receiveStatus === 3 || (item.receiveStatus == 1 && item.sendingType == '回寄')) {
					return {
						'background-color': '#fdfbdd',
						'border-color': '#67C23A',
						color: '#67C23A'
					}
				} else {
					return {
						'background-color': '#fef0f0',
						'border-color': '#fde2e2',
						color: '#000000'
					}
				}
			},
			colorordersStatusType(item) {
				switch (item) {
					//    
					case 1:
					case 4:
						return {
							'background-color': '#fdf6ec', 'border-color': '#00BF5B', color: '#00BF5B'
						} //success
					case 3:
						return {
							'background-color': '#fdf6ec', 'border-color': '#fde2e2', color: '#FF4646'
						} //danger
					case 6:
						return {
							'background-color': '#fdf6ec', 'border-color': '#faecd8', color: '#266EFF'
						} //'warning'
					case 7:
					case 8:
					case 9:
					case 11:
					case 10:
						return {
							'background-color': '#fdf6ec', 'border-color': '#faecd8', color: '#266EFF'
						} //'warning'
					default:
						return {
							'background-color': '#fdf6ec', 'border-color': '#f4f4f5', color: '#999999'
						} //info
				}
			},
			colorType(item) {
				switch (item) {
					case 0:
						return {
							'background-color': '#00BF5B', 'border-color': '#e1f3d8', color: '#FFFFFF'
						} //success
					case 1:
						return {
							'background-color': '#FF4646', 'border-color': '#fde2e2', color: '#FFFFFF'
						} //danger
					case 2:
						return {
							'background-color': '#00BF5B', 'border-color': '#e1f3d8', color: '#FFFFFF'
						} //success
					case 3:
						return {
							'background-color': '#f4f4f5', 'border-color': '#e9e9eb', color: '#266EFF'
						} //info
					case 4:
						return {
							'background-color': '#f4f4f5', 'border-color': '#e9e9eb', color: '#266EFF'
						} //info
					case 5:
						return {
							'background-color': '#FF4646', 'border-color': '#fde2e2', color: '#FFFFFF'
						} //danger
					case 6:
						return {
							'background-color': '#fdf6ec', 'border-color': '#faecd8', color: '#266EFF'
						} //'warning'
					default:
						return {
							'background-color': '#00BF5B', 'border-color': '#e1f3d8', color: '#FFFFFF'
						} //success
				}
			},

		}
	}
</script>

<style lang="scss" scoped>
	.redPrice {
		font-size: 28rpx;
		margin: 0 4rpx;
		color: red;
	}

	.color0 {
		background: linear-gradient(180deg, #5DDFFA 0%, #1E68E3 100%);
		color: #ffffff;
		background-clip: text;
		font-weight: 700;
		-webkit-background-clip: text;
		-webkit-text-fill-color: transparent;
		display: inline-block;
	}

	.color1 {
		background: linear-gradient(180deg, #4CE4D5 0%, #0FB6D2 100%);
		color: #ffffff;
		background-clip: text;
		font-weight: 700;
		-webkit-background-clip: text;
		-webkit-text-fill-color: transparent;
		display: inline-block;

	}

	.color2 {
		background: linear-gradient(180deg, #74ADFE 0%, #7E61EF 99%);
		color: #ffffff;
		font-weight: 700;
		background-clip: text;
		-webkit-background-clip: text;
		-webkit-text-fill-color: transparent;
		display: inline-block;

	}

	.color3 {
		background: linear-gradient(180deg, #4CE4D5 0%, #0FB6D2 100%);
		color: #ffffff;
		background-clip: text;
		font-weight: 700;
		-webkit-background-clip: text;
		-webkit-text-fill-color: transparent;
		display: inline-block;
	}

	.cardItem.first {
		margin-top: 0rpx;
	}

	.cardItem {
		position: relative;
		margin: 0 10rpx;
		padding: 16rpx 12rpx;
		box-shadow: 2rpx 2rpx 8rpx 8rpx rgba(32, 108, 228, 0.3);
		border-radius: 8rpx;
		margin-top: 48rpx;
		color: rgba(51, 51, 51, 1);

		&_top {
			display: flex;
			align-items: center;
			justify-content: space-between;
			line-height: 56rpx;

			&_left {
				display: flex;
				align-items: center;

				&_btn {
					cursor: pointer;
					padding: 2rpx 16rpx;
					height: 48rpx;
					font-size: 26rpx;
					line-height: 42rpx;
					border: 2rpx solid #266EFF;
					border-radius: 6rpx;
					color: #266EFF;
					margin-right: 18rpx;
				}

				&_btn:last-child {
					margin: 0rpx;
				}
			}

			&_right {
				display: flex;
				align-items: center;

				&_btn {
					padding: 0 6rpx;
					border-radius: 6rpx;
					margin-right: 8rpx;
					font-size: 26rpx;
					line-height: 40rpx;
					transform: scale(0.9);
					border: 2rpx solid #fff;
				}

				&_btn:last-child {
					margin: 0rpx;
				}

			}

		}

		&_price {
			color: rgba(42, 139, 239, 1);
			font-size: 28rpx;
			line-height: 40rpx;
			padding-left: 12rpx;
		}

		&_infosContaines {
			padding: 20rpx 12rpx;
			font-size: 26rpx;

			&_content {
				border-top: 2rpx solid rgba(197, 197, 197, 1);
				padding-top: 20rpx;

				&_item:first-child {
					margin-top: 0rpx;
				}

				&_item {
					margin-top: 10rpx;
					display: flex;
					font-size: 26rpx;
					line-height: 40rpx;

					&_label {
						color: #666666;
						width: 140rpx;
						margin-right: 12rpx;
					}

					&_title {
						color: #111111;

						&_infos {
							display: flex;
							flex-wrap: wrap;
							align-items: center;

							&_name {
								font-weight: 700;
							}

							&_line {
								width: 2rpx;
								height: 20rpx;
								background: rgba(168, 168, 168, 1);
								margin: 0 10rpx;
							}
						}
					}
				}
			}

		}

		&_bottom {
			&_btnGroup {
				display: flex;
				align-items: center;
				flex-wrap: wrap;
				padding: 10rpx;

				&_item {
					// padding: 10rpx;

					&_btn {
						cursor: pointer;
						padding: 2rpx 16rpx;
						height: 48rpx;
						font-size: 26rpx;
						line-height: 42rpx;
						border: 2rpx solid #266EFF;
						border-radius: 6rpx;
						color: #266EFF;
						margin-right: 20rpx;
					}
				}
			}
		}
	}
</style>